package com.example.springbott.wx_service;

import com.example.springbott.bean.MarketCategory;
import com.example.springbott.bean.MarketCategoryExample;
import com.example.springbott.bean.zeng.WXCatalogCurrentVo;
import com.example.springbott.bean.zeng.WXCatalogIndexVo;
import com.example.springbott.mapper.MarketCategoryMapper;
import com.example.springbott.util.Count;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author: zeng
 * @Description:
 * @date:
 */

@Service
public class WXCatalogServiceImpl implements WXCatalogService {
    @Autowired
    MarketCategoryMapper marketCategoryMapper;

    @Override
    public WXCatalogCurrentVo current(Integer id) {
        //获得一级类目
        MarketCategory marketCategory = marketCategoryMapper.selectByPrimaryKey(id);

        //获得当前子类目
        MarketCategoryExample marketCategoryExample = new MarketCategoryExample();
        MarketCategoryExample.Criteria criteria = marketCategoryExample.createCriteria();
        criteria.andPidEqualTo(id).andDeletedEqualTo(false);
        List<MarketCategory> marketCategories = marketCategoryMapper.selectByExample(marketCategoryExample);

        //封装返回对象
        WXCatalogCurrentVo wxCatalogCurrentVo = new WXCatalogCurrentVo();
        wxCatalogCurrentVo.setCurrentCategory(marketCategory);
        wxCatalogCurrentVo.setCurrentSubCategory(marketCategories);

        return wxCatalogCurrentVo;

    }

    @Override
    public WXCatalogIndexVo index() {
        //获得L1级别所有类目
        MarketCategoryExample marketCategoryExample = new MarketCategoryExample();
        MarketCategoryExample.Criteria criteria = marketCategoryExample.createCriteria();
        criteria.andLevelEqualTo(Count.LEVELOFL1);
        criteria.andDeletedEqualTo(false);
        List<MarketCategory> CategoryList = marketCategoryMapper.selectByExample(marketCategoryExample);
        
        //获取当前类目
        MarketCategory currentCategory = CategoryList.get(Count.CATALOG_DEFAULT);
        Integer pid = currentCategory.getId();

        //获取当前类目的子类目
        MarketCategoryExample example = new MarketCategoryExample();
        MarketCategoryExample.Criteria criteria1 = example.createCriteria();
        criteria1.andPidEqualTo(pid).andLevelEqualTo(Count.LEVELOFL2).andDeletedEqualTo(false);
        List<MarketCategory> MarketCategory = marketCategoryMapper.selectByExample(example);
        // List<MarketCategory> MarketCategory2 = marketCategoryMapper.selectByZeng(pid, "L2", false);
        //封装返回对象
        WXCatalogIndexVo wxCatalogIndexVo = new WXCatalogIndexVo();
        wxCatalogIndexVo.setCurrentCategory(currentCategory);
        wxCatalogIndexVo.setCategoryList(CategoryList);
        wxCatalogIndexVo.setCurrentSubCategory(MarketCategory);

        return wxCatalogIndexVo;

    }
}
